
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/22/2011 16:08:51
-- Generated from EDMX file: D:\Study\programming\DotNet\LearnByTest\CSharp\database\PlayEntityFramework\OrderIT\Entity\OrderIT.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [LearnEF];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Customer_inherits_Company]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Companies_Customer] DROP CONSTRAINT [FK_Customer_inherits_Company];
GO
IF OBJECT_ID(N'[dbo].[FK_Supplier_inherits_Company]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Companies_Supplier] DROP CONSTRAINT [FK_Supplier_inherits_Company];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Companies]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Companies];
GO
IF OBJECT_ID(N'[dbo].[Companies_Customer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Companies_Customer];
GO
IF OBJECT_ID(N'[dbo].[Companies_Supplier]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Companies_Supplier];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Companies'
CREATE TABLE [dbo].[Companies] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [BillAddress_Address] nvarchar(30)  NOT NULL,
    [BillAddress_City] nvarchar(20)  NOT NULL,
    [BillAddress_Country] nvarchar(20)  NOT NULL,
    [BillAddress_ZipCode] nvarchar(20)  NOT NULL,
    [ShipAddress_Address] nvarchar(30)  NOT NULL,
    [ShipAddress_City] nvarchar(20)  NOT NULL,
    [ShipAddress_Country] nvarchar(20)  NOT NULL,
    [ShipAddress_ZipCode] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'Companies_Customer'
CREATE TABLE [dbo].[Companies_Customer] (
    [Id] int  NOT NULL
);
GO

-- Creating table 'Companies_Supplier'
CREATE TABLE [dbo].[Companies_Supplier] (
    [Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Companies'
ALTER TABLE [dbo].[Companies]
ADD CONSTRAINT [PK_Companies]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Companies_Customer'
ALTER TABLE [dbo].[Companies_Customer]
ADD CONSTRAINT [PK_Companies_Customer]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Companies_Supplier'
ALTER TABLE [dbo].[Companies_Supplier]
ADD CONSTRAINT [PK_Companies_Supplier]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Id] in table 'Companies_Customer'
ALTER TABLE [dbo].[Companies_Customer]
ADD CONSTRAINT [FK_Customer_inherits_Company]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Companies]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Companies_Supplier'
ALTER TABLE [dbo].[Companies_Supplier]
ADD CONSTRAINT [FK_Supplier_inherits_Company]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Companies]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------